

import {
  ADD_COUNTER,
  ADD_IN_CART
} from './mutation-type'
function SaveCar(data) {
  localStorage.setItem('car', JSON.stringify(data))
}
export default {
  [ADD_COUNTER](state, payload) {
    payload.count++

  },
  [ADD_IN_CART](state, payload) {
    payload.check = true;
    payload.count = 1;
    state.carList.push(payload)
  },
  remove_in_cart(state, payload) {
    state.carList = state.carList.filter(v => v.iid !== payload.iid)
  },
  editCartCheckAll(state, flag) {
    state.carList.map(v => {
      v.check = flag
    })
    SaveCar(state.carList)
  },
  editCartCheck(state, id) {
    state.carList.map(v => {
      if (v.iid === id) {
        v.check = !v.check
      }
    })
    SaveCar(state.carList)
  }
}

